package com.wt.admin.service.ai.impl.agents;

import cn.hutool.json.JSONUtil;
import com.wt.admin.domain.dto.ai.AgentsInfoDTO;
import com.wt.admin.domain.entity.ai.MCPEntity;
import com.wt.admin.domain.entity.ai.ModelConfigEntity;
import com.wt.admin.service.ai.impl.mcp.MCPStart;
import org.springframework.ai.tool.ToolCallbackProvider;

import java.util.List;
import java.util.Map;

public interface AgentsBuilderService {


    AgentsManager.Agent builder(AgentsInfoDTO agents, ModelConfigEntity model, List<MCPEntity> mcpEntities);


    default ToolCallbackProvider[] getToolCallbackProvider(MCPStart mcpStart, MCPEntity mcpEntities) {
        return switch (mcpEntities.getTag()) {
            case 0 -> new ToolCallbackProvider[]{
                    mcpStart.builderMcpClientSTDIO(mcpEntities.getContent(), mcpEntities.isSync())
            };
            case 1 -> {
                List<Map> configList = JSONUtil.toList(mcpEntities.getContent(), Map.class);
                yield configList.stream()
                        .map(k -> mcpStart.builderMcpClientSSE(
                                k.get("server").toString(),
                                k.get("url").toString(),
                                mcpEntities.isSync()
                        ))
                        .toArray(ToolCallbackProvider[]::new); // 使用正确泛型转换
            }
            case 2 -> {
                List<Map> configList = JSONUtil.toList(mcpEntities.getContent(), Map.class);
                yield configList.stream()
                        .map(k -> mcpStart.builderMcpClientFlux(
                                k.get("server").toString(),
                                k.get("url").toString(),
                                mcpEntities.isSync()
                        ))
                        .toArray(ToolCallbackProvider[]::new); // 使用正确泛型转换
            }
            default -> null; // 返回空数组替代null更安全
        };
    }

}
